home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / FLAMER.ZIP / FLAMER.ASM next >
Assembly Source File  |  1996-06-10  |  9KB  |  400 lines

  1. ;
  2. ;       FLAMER!         MULTI-PALETTE VERSION           386+ only, sorry!
  3. ;                       ---------------------
  4. ;                       by E.Vaughan May 1996
  5. ;
  6. ;       please mail any comments, etc. to: emil0@aol.com
  7.  
  8. comment *  This is public domain software. Its been done before but here is 
  9.        my version. Feel free to make it better if you want. Please send 
  10.        any comments or suggestions to my address above - I would very
  11.        much appreciate it if you send me any modifications you make to
  12.        the source code. Cheers!
  13.     
  14. DISCLAIMER: there is no disclaimer. If this fucks up your machine, I don't
  15.         care - just try and sue me... :) 
  16.     *
  17. ;----------------------------------------------------------------------------
  18.      DOSSEG          
  19.     .MODEL SMALL
  20.     .STACK 100
  21.  
  22. .DATA
  23.  
  24. ; Different palettes for the flame
  25.  
  26. RAINBOW = 1        ; *** choose palette here ***
  27.  
  28. palette label word
  29.  
  30. IFDEF (NORMAL)          ; the "normal" flame palette
  31.  
  32.     db 0, 0, 0          ; set black to red
  33.     i = 3
  34.     rept 15
  35.        db i, 0, 0
  36.        i = i + 4
  37.     endm
  38.     db 63, 0, 0         ; set red to yellow
  39.     i = 1
  40.     rept 31
  41.        db 63, i, 0
  42.        i = i + 2
  43.     endm
  44.     db 63, 63, 0        ; set yellow to white
  45.     i = 1
  46.     rept 31
  47.        db 63, 63, i
  48.        i = i + 2
  49.     endm
  50.     db 528 dup (63)     ; set remaining colors to white
  51. ENDIF
  52.  
  53. IFDEF (TESTER)     ; use this palette to see how the flame works
  54.  
  55.     db 0, 0, 0
  56.     rept 85
  57.        db 63, 0, 0
  58.        db 0, 63, 0
  59.        db 0, 0, 63
  60.     endm    
  61. ENDIF
  62.  
  63. IFDEF (GAS1)    ; I don't like this one much
  64.  
  65.     db 0, 0, 0          
  66.     i = 1
  67.     rept 31
  68.        db 0, 0, i
  69.        i = i + 2
  70.     endm
  71.     db 0, 0, 63         
  72.     i = 3
  73.     rept 15
  74.        db i, 0, 63-i
  75.        i = i + 4
  76.     endm
  77.     db 63, 0, 0        
  78.     i = 1
  79.     rept 31
  80.        db 63, i, i
  81.        i = i + 2
  82.     endm
  83.     db 528 dup (63)     
  84. ENDIF
  85.  
  86. IFDEF (GAS2)    ; some people really like this one         
  87.  
  88.     db 0, 0, 0
  89.     i = 1
  90.     rept 31
  91.        db 0, 0, i
  92.        i = i + 2
  93.     endm
  94.     i = 1
  95.     rept 48
  96.        db 0, 0, 63-i
  97.        i = i +1
  98.     endm
  99.     db 528 dup (0)          ; NOTE: remaining colors set to black
  100. ENDIF
  101.  
  102. IFDEF (GREEN)    ; quite a nice palette, this one.
  103.  
  104.     db 0, 0, 0          ; set black to green                                  
  105.     i = 1
  106.     rept 31
  107.        db 0, i, 0
  108.        i = i + 2
  109.     endm
  110.     i = 1               ; set green to white
  111.     rept 48
  112.        db i, 63, i
  113.        i = i + 1
  114.     endm
  115.      
  116.     db 528 dup (63)     ; set remaining colors to white
  117. ENDIF
  118.  
  119. IFDEF (YELLOW)        ; it is what is says!        
  120.  
  121.     db 0, 0, 0
  122.     i = 1
  123.     rept 31
  124.        db i, i, 0
  125.        i = i + 2
  126.     endm
  127.     i = 1
  128.     rept 48
  129.        db 63, 63, i
  130.        i = i +1
  131.     endm
  132.     db 528 dup (63) 
  133. ENDIF
  134.  
  135. IFDEF (PURPLE)        ; no comment.
  136.  
  137.     db 0, 0, 0          ; set black to purple                                  
  138.     i = 1
  139.     rept 31
  140.        db i, 0, i
  141.        i = i + 2
  142.     endm
  143.     i = 1               ; set purple to white
  144.     rept 48
  145.        db 63, i, 63
  146.        i = i + 1
  147.     endm
  148.      
  149.     db 528 dup (63)
  150. ENDIF
  151.  
  152. IFDEF (RAINBOW)        ; cool rainbow palette
  153.  
  154.     db 0, 0, 0
  155.     i = 1
  156.     rept 20        ; set black - purple
  157.        db i, 0, i
  158.        i = i + 3
  159.     endm 
  160.     rept 10        ; set purple - blue
  161.        db i, 0, 63
  162.        i = i - 6
  163.     endm
  164.     i = 1
  165.     rept 10        ; set blue - green
  166.        db 0, i, 63-i
  167.        i = i + 6
  168.     endm
  169.     i = 1
  170.     rept 30        ; set green - white
  171.        db i, 63, i
  172.        i = i + 2
  173.     endm
  174.     db 555 dup (63)
  175. ENDIF
  176.  
  177. random_seed1    dw 0    ; used by random number generator
  178. random_seed2    dw 0
  179.         
  180. message label byte        
  181. db "Flamer! (c) E.Vaughan May 1996", 10, 10, 13
  182. db "Please me send any comments, suggestions, cash, " 
  183. db "credit card numbers... :)", 10, 10, 13
  184. db "You can reach me at emil0@aol.com", 10, 10, 13, "$"
  185.  
  186. .CODE
  187. .386    ; could be 286-, but I used 32-bit string instructions.
  188.     ; replace these with word instructions for 286- machines.
  189.  
  190. main    PROC    NEAR
  191.  
  192. start:
  193.     mov     ax, seg @DATA   ; sort out ds segment
  194.     mov     ds, ax
  195.     cld
  196.  
  197.     mov     ax, 2C00h       ; set random number generator seeds
  198.     int     21h             ; call DOS get time function
  199.     mov     word ptr @DATA:random_seed1, cx
  200.     mov     word ptr @DATA:random_seed2, dx
  201.     
  202.     xor     ax, ax          ; BOTH arrays _must_ be zeroed!!
  203.     push    ds
  204.     pop     es
  205.     mov     di, offset flame_map
  206.     mov     cx, 1536        ; this is the size of the arrays in dwords
  207.     rep     stosd
  208.     mov     di, offset new_flame_map
  209.     mov     cx, 1536
  210.     rep     stosd
  211.  
  212.     mov     ax, 0A000h
  213.     mov     es, ax          ; set es to VGA video segment
  214.     
  215.     mov     ax, 0013h
  216.     int     10h             ; switch to VGA mode 13h!
  217.     
  218.     mov     bx, offset palette     ; put palette name here!   
  219.     call    set_palette
  220.  
  221. @main_loop:
  222.  
  223.     push    es
  224.     push    ds
  225.     pop     es              ; save es, and transfer ds to es
  226.     
  227.     mov     si, offset @DATA:flame_map
  228.     add     si, 127*48+10   
  229.     mov     cx, 12          ; number of hot_spots - changeable
  230.     push    si              ; save a copy of si
  231. @hot_spots_loop:
  232.     pop     si
  233.     push    si
  234.     mov     bx, 28    ; determines how wide the hot-spot area is
  235.     call    random
  236.     add     si, ax
  237.     mov     al, 200      ; you can change this to alter flame height
  238.     mov     ds:[si], al
  239.     loop    @hot_spots_loop
  240.     pop     si                      ; sort out stack!
  241.  
  242.     mov     si, offset @DATA:flame_map
  243.     add     si, 49
  244.     mov     di, offset @DATA:new_flame_map
  245.     add     di, 49
  246.     mov     dx, 127          ; row counter
  247. @rows1:
  248.     mov     cx, 46          ; columns counter
  249. @cols1:
  250.     xor     ax, ax          ; get average of the 8 surrounding pixels
  251.     xor     bx, bx          ; pixels are taken from one BELOW 
  252.     mov     al, ds:[si-1]
  253.     mov     bl, ds:[si]
  254.     add     ax, bx
  255.     mov     bl, ds:[si+1]
  256.     add     ax, bx
  257.     mov     bl, ds:[si+47]
  258.     add     ax, bx
  259.     mov     bl, ds:[si+49]
  260.     add     ax, bx
  261.     mov     bl, ds:[si+95]
  262.     add     ax, bx
  263.     mov     bl, ds:[si+96]
  264.     add     ax, bx
  265.     mov     bl, ds:[si+97] 
  266.     add     ax, bx
  267.     shr     ax, 3   
  268.     mov     es:[di], al     ; es still set to ds!
  269.     inc     si
  270.     inc     di
  271.     loop    @cols1
  272.     inc     si              ; note: the outside edges are left alone.
  273.     inc     si
  274.     inc     di
  275.     inc     di
  276.     dec     dx              ; dx counts rows
  277.     jnz     @rows1
  278.  
  279.     mov     si, offset @DATA:new_flame_map
  280.     mov     di, offset @DATA:flame_map
  281.     mov     cx, 1536
  282.     rep     movsd           ; update new flames map
  283.     pop     es              ; restore video segment 
  284.  
  285.     mov     dx, 03DAh       ; VGA port used to get retrace state
  286.  
  287. comment *    uncomment this to sync flame with vertical retrace
  288.  
  289. @retrw:
  290.     in      al, dx
  291.     test    al, 8
  292.     jz      @retrw          ; wait for a vertical retrace
  293.  
  294.     *
  295.  
  296.     mov     si, offset @DATA:flame_map
  297.     mov     di, 36*320+160-24 
  298.     mov     bx, 127          ; row counter
  299. @rows2:
  300.     mov     cx, 12
  301.     rep     movsd            ; write flame bitmap to video memory
  302.     add     di, 272
  303.     dec     bx
  304.     jnz     @rows2
  305.  
  306.     in      al, 60h         ; wait until user presses escape
  307.     cmp     al, 1
  308.     jne     @main_loop
  309.         
  310. @finished:
  311.  
  312.     mov     ax, 0003h       ; return to text mode
  313.     int     10h
  314.         
  315.     mov     dx, offset message  ; display message
  316.     mov     ah, 9
  317.     int     21h
  318.     
  319.     mov     ax, 0C06h
  320.     mov     dl, 0
  321.     int     21h             ; GOOD way of flushing keyboard buffer
  322.                 ; any comments?
  323.     
  324.     mov     ax, 4C00h       ; terminate program
  325.     int     21h
  326.  
  327. main    ENDP
  328.  
  329. set_palette     PROC    NEAR
  330.  
  331.     ; sets VGA palette - bx holds palette image offset!
  332.     
  333.     push    ax cx dx si di es       ; commas may be needed with MASM
  334.     mov     si, bx
  335.     mov     dx, 03C6h
  336.     mov     al, 0FFh
  337.     out     dx, al
  338.     inc     dx
  339.     inc     dx
  340.     mov     al, 0           ; start with color 0
  341.     out     dx, al
  342.     inc     dx
  343.     mov     cx, 768
  344.     rep     outsb           ; blast palette to VGA
  345.  
  346.     mov     ax, 0A000h      ; draws the palette at the top of the screen
  347.     mov     es, ax
  348.     xor     di, di
  349.     mov     cx, 256
  350.     mov     al, 0
  351. @@loop1:
  352.     stosb
  353.     inc     al
  354.     loop    @@loop1
  355.     
  356.     pop     es di si dx cx ax
  357.     ret
  358.     
  359. set_palette     ENDP
  360.  
  361. random  PROC    NEAR    ; good random proc - sorry, I can't remember
  362.             ;       where this originated from.
  363.  
  364.     push    cx dx si di
  365.     mov     cx, bx
  366.     mov     ax, word ptr ds:random_seed1
  367.     mov     bx, word ptr ds:random_seed2
  368.     mov     si, ax
  369.     mov     di, bx
  370.     mov     dl, ah
  371.     mov     ah, al
  372.     mov     al, bh
  373.     mov     bh, bl
  374.     xor     bl, bl
  375.     rcr     dl, 1
  376.     rcr     ax, 1
  377.     rcr     bx, 1
  378.     add     bx, di
  379.     adc     ax, si
  380.     add     bx, 62E9h
  381.     adc     ax, 3619h
  382.     mov     word ptr ds:random_seed2, ax
  383.     mov     word ptr ds:random_seed1, bx
  384.     xor     dx, dx
  385.     div     cx        ; slow DIV instruction here...
  386.     mov     ax, dx
  387.     pop     di si dx cx
  388.     ret
  389.  
  390. random  ENDP
  391.  
  392. .DATA
  393.  
  394. flame_map       db 6144 dup (?)       ; large arrays
  395. new_flame_map   db 6144 dup (?)
  396.  
  397.     END     start
  398.  
  399.             *** END OF FILE ***        
  400.